package com.guigu.tms.aggregation.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.guigu.tms.aggregation.mapper.TransportOrderMapper;
import com.guigu.tms.aggregation.mapper.TransportOrderTaskMapper;
import com.guigu.tms.commons.aggregation.entity.TaskTransport;
import com.guigu.tms.aggregation.mapper.TaskTransportMapper;
import com.guigu.tms.aggregation.service.ITaskTransportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.tms.commons.aggregation.entity.TransportOrder;
import com.guigu.tms.commons.aggregation.entity.TransportOrderTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 运输任务表 服务实现类
 * </p>
 *
 * @author wj
 * @since 2022-10-21
 */
@Service
public class TaskTransportServiceImpl extends ServiceImpl<TaskTransportMapper, TaskTransport> implements ITaskTransportService {

    @Autowired
    private TaskTransportMapper taskTransportMapper;
    @Autowired
    private TransportOrderTaskMapper transportOrderTaskMapper;
    @Autowired
    private TransportOrderMapper transportOrderMapper;

    @Override
    public boolean createTaskTransport(TaskTransport taskTransport) {
        taskTransportMapper.insert(taskTransport);
        for (String transportOrderId : taskTransport.getTransportOrderIds()) {
            TransportOrderTask transportOrderTask = new TransportOrderTask();
            transportOrderTask.setTransportOrderId(transportOrderId);
            transportOrderTask.setTransportTaskId(taskTransport.getId());
            transportOrderTaskMapper.insert(transportOrderTask);
        }
        return true;
    }

    @Override
    public boolean updateTaskTransport(TaskTransport taskTransport) {
        taskTransportMapper.updateById(taskTransport);
        for (String transportOrderId : taskTransport.getTransportOrderIds()) {
            //根据运单编号修改运单状态
            TransportOrder transportOrder = new TransportOrder();
            transportOrder.setId(transportOrderId);
            transportOrder.setStatus(3);
            transportOrderMapper.updateById(transportOrder);
        }
        return true;
    }

}
